package com.thesis.teacher.controller;

import com.thesis.manage.common.controller.AbstractController;
import com.thesis.manage.common.utils.Result;
import com.thesis.manage.service.constant.ErrorMessage;
import com.thesis.manage.service.model.StateCodeEnum;
import com.thesis.teacher.feign.UserService;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * @author php
 * @date 2018/2/9
 */
public class BaseController extends AbstractController {
    @Resource
    private UserService userService;

    Result getUser() {
        String token = getToken();
        Result result = this.userService.findUserByToken(token);
        boolean isExist = result != null && result.getStatus() == StateCodeEnum.SUCCESS.getValue().intValue() && result.getData() != null;
        Assert.state(isExist, ErrorMessage.USER_NO_LOGIN);
        return result;
    }
}
